package com.tyk.bookstore.back.product.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.tyk.bookstore.back.common.core.model.result.R;
import com.tyk.bookstore.back.product.model.query.BookStatisticAddQuery;
import com.tyk.bookstore.back.product.model.query.BookStatisticPageQuery;
import com.tyk.bookstore.back.product.model.query.BookStatisticUpdateQuery;
import com.tyk.bookstore.back.product.model.vo.BookStatisticPageVo;
import com.tyk.bookstore.back.product.model.vo.BookStatisticVo;
import com.tyk.bookstore.back.product.service.BookStatisticService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

/**
 * @author tyk
 * @description 书籍统计信息
 */
@Tag(name = "商品管理/统计信息管理", description = "书籍统计信息管理")
@RequiredArgsConstructor
@RestController
@RequestMapping("api/product/statistic")
public class BookStatisticController {

    private final BookStatisticService bookStatisticService;

    @Operation(summary = "查询书籍统计信息详情", description = "查询书籍统计信息详情")
    @SaCheckPermission("product:statistic:get")
    @GetMapping("{id}")
    public R<BookStatisticVo> getById(
            @Schema(description = "书籍统计信息ID")
            @NotNull @Min(value = 1)
            @PathVariable Long id
    ) {
        return R.ok(bookStatisticService.getById(id));
    }

    @Operation(summary = "分页查询书籍统计信息", description = "分页查询书籍统计信息")
    @SaCheckPermission("product:statistic:page")
    @GetMapping("page")
    public R<BookStatisticPageVo> getPage(
            @Schema(description = "书籍统计信息分页查询参数")
            @ParameterObject
            @Validated BookStatisticPageQuery query
    ) {
        return R.ok(bookStatisticService.getPage(query));
    }

    @Operation(summary = "添加书籍统计信息", description = "添加书籍统计信息")
    @SaCheckPermission("product:statistic:add")
    @PostMapping
    public R<Object> add(
            @Validated @RequestBody BookStatisticAddQuery query
    ) {
        bookStatisticService.add(query);
        return R.ok();
    }

    @Operation(summary = "更新书籍统计信息", description = "更新书籍统计信息")
    @SaCheckPermission("product:statistic:update")
    @PutMapping
    public R<Object> updateById(
            @Validated @RequestBody BookStatisticUpdateQuery query
    ) {
        bookStatisticService.updateById(query);
        return R.ok();
    }

    @Operation(summary = "删除书籍统计信息", description = "删除书籍统计信息")
    @SaCheckPermission("product:statistic:delete")
    @DeleteMapping("{id}")
    public R<Object> deleteById(
            @Schema(description = "书籍统计信息ID")
            @Min(value = 1) @NotNull
            @PathVariable Long id
    ) {
        bookStatisticService.deleteById(id);
        return R.ok();
    }

    @Operation(summary = "批量删除书籍统计信息", description = "批量删除书籍统计信息")
    @SaCheckPermission("product:statistic:delete")
    @DeleteMapping
    public R<Object> deleteBatchByIdSet(
            @Schema(description = "书籍统计信息ID列表")
            @NotEmpty @NotNull Set<Long> idList
    ) {
        bookStatisticService.deleteBatchByIdSet(idList);
        return R.ok();
    }

}

